//
//  PersonalCollectionView.m
//  BeautifulLockerRoom
//
//  Created by mac on 16/8/1.
//  Copyright © 2016年 Winny. All rights reserved.
//

#import "PersonalCollectionView.h"
#import "CollectionViewCell.h"
#import "ShopViewController.h"

@interface PersonalCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation PersonalCollectionView

-(instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    
    if (self= [super initWithFrame:frame collectionViewLayout:layout]) {
        [self registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        
        self.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
        self.delegate = self;
        self.dataSource = self;
        
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return _dataArray.count;
}


- (CollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    DataModel * model = _dataArray[indexPath.item];
    
    cell.taobao_promo_price.text = [NSString stringWithFormat:@"%@%@",model.money_symbol,model.taobao_promo_price];
    cell.taobao_price.text = [NSString stringWithFormat:@"%@%@",model.money_symbol,model.taobao_price];
    cell.taobao_title.text = model.taobao_title;
    cell.tagView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.tag_url]]];
    cell.imgView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.taobao_pic_url]]];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
{
    DataModel * model = _dataArray[indexPath.item];
    ShopViewController * vc = [[ShopViewController alloc]init];
    vc.view.frame = CGRectMake(0, 0, WINDOWWIDTH, WINDOWHEIGHT);
    vc.url = model.taobao_url;
    UIWindow * window = [[UIApplication sharedApplication].delegate window];
    [window.rootViewController presentViewController:vc animated:YES completion:nil];
}

@end
